layui.define(
  ["table", "laydate", "upload", "element", "layer"],
  function (exports) {
    var table = layui.table,
      $ = layui.$,
      laydate = layui.laydate,
      upload = layui.upload,
      form = layui.form,
      element = layui.element,
      layer = layui.layer;
    $("#urltop").hide();
    realTimeSClick("#reviewBacklogHref", "0");
    realTimeSClick("#reviewDonelogHref", "1");
    function realTimeSClick(elem, data) {
      $(elem).click(function () {
        layui.sessionData("technicalCategory", {
          key: "key",
          value: data,
        });
        $(this).attr("lay-href", "./pages/technicalReview.html");
      });
    }

    // function reviewHrefClick(elem, data) {
    //   console.log(elem);
    //   $(elem).click(function () {
    //     layui.data("technicalCategory", {
    //       key: "key",
    //       value: data,
    //     });
    //     $(this).attr("lay-href", "./pages/technicalReview.html");
    //   });
    // }

    $(".noticeMeetingTotal").html(layui.sessionData("noticeMeetingLength").key);
    //多文件列表示例
    function initFileMultipleCtrl() {
      var fileSize = "";
      var demoListView = $("#demoList");
      var uploadListIns = upload.render({
        elem: "#testList",
        url: base_url + "/agenda/uploadAgendaAttachFile",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        accept: "file",
        multiple: true,
        auto: false,
        bindAction: "#testListAction",
        choose: function (obj) {
          var that = this;
          var files = (this.files = obj.pushFile()); //将每次选择的文件追加到文件队列
          //读取本地文件
          obj.preview(function (index, file, result) {
            fileSize = (file.size / 1024).toFixed(1);
            var tr = $(
              [
                '<tr id="upload-' + index + '">',
                "<td>" + file.name + "</td>",
                "<td>" + (file.size / 1024).toFixed(1) + "kb</td>",
                '<td><div class="layui-progress" lay-filter="progress-demo-' +
                  index +
                  '"><div class="layui-progress-bar" lay-percent=""></div></div></td>',
                "<td>等待上传</td>",

                "<td>" +
                  '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>',
                '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>',
                "</td>",
                "</tr>",
              ].join("")
            );

            //单个重传
            tr.find(".demo-reload").on("click", function () {
              obj.upload(index, file);
            });

            //删除
            tr.find(".demo-delete").on("click", function () {
              delete files[index]; //删除对应的文件
              tr.remove();
              uploadListIns.config.elem.next()[0].value = ""; //清空 input file 值，以免删除后出现同名文件不可选
            });

            demoListView.append(tr);
            element.render("progress"); //渲染新加的进度条组件
          });
        },
        before: function () {
          this.data = {
            uuid: addUid,
            fileSize: fileSize + "kb",
          };
        },
        progress: function (n, elem, e, index) {
          console.log("进度：" + n + "%");
          element.progress("progress-demo-" + index, n + "%"); //执行进度条。n 即为返回的进度百分比
        },
        done: function (res, index, upload) {
          if (res.code == 200) {
            //上传成功
            var tr = demoListView.find("tr#upload-" + index),
              tds = tr.children();
            tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
            tds.eq(4).html(""); //清空操作
            $("#url").val(res.data); //上传成功后把得到的参数赋值给我这里的url路径这个文本框中
            return delete this.files[index]; //删除文件队列已经上传成功的文件
          }
          this.error(index, upload);
        },
        error: function (index, upload) {
          var tr = demoListView.find("tr#upload-" + index),
            tds = tr.children();
          tds.eq(3).html('<span style="color: #FF5722;">上传失败</span>');
          tds.eq(4).find(".demo-reload").removeClass("layui-hide"); //显示重传
        },
      });
    }
    //开始日期
    function initDateCtrl() {
      var begD = laydate.render({
        elem: "#startDatePerson",
        type: "date",
        value: new Date(),
        min: new Date().toLocaleString(),
        format: "yyyy-MM-dd",
        done: function (value, date) {
          $("#starTimePerson").focus();
          if (value != "") {
            date.month = date.month - 1;
            endD.config.min = date;
          } else {
            endD.config.min = begD.config.min;
          }
        },
        ready: function (value) {
          disabled_date(value, $("#appointmentDate").val());
        },
        change: function (value, date) {
          disabled_date(date, $("#appointmentDate").val());
        },
      });
      //结束日期
      var endD = laydate.render({
        elem: "#endDatePerson",
        type: "date",
        format: "yyyy-MM-dd",
        min: new Date().toLocaleString(),
        done: function (value, date) {
          $("#endTime").focus();
          if (value != "") {
            date.month = date.month - 1;
            begD.config.max = date;
          } else {
            begD.config.max = endD.config.max;
          }
        },
        ready: function (value) {
          disabled_date(value, $("#appointmentDate").val());
        },
        change: function (value, date) {
          disabled_date(date, $("#appointmentDate").val());
        },
      });
      var startTimme = "";
      // 开始时间
      var begT = laydate.render({
        elem: "#starTimePerson",
        type: "time",
        format: "HH:mm",
        ready: function (value) {
          formatminutes($("#startDatePerson").val());
        },
        done: function (value, date) {
          startTimme = date.hours + ":" + date.minutes;
          console.log(startTimme);
          $("#endDatePerson").val($("#startDatePerson").val());
          var hours = date.hours + 1;
          var minutes = date.minutes;
          if (hours < 10) {
            hours = "0" + hours;
          }
          if (minutes < 10) {
            minutes = "0" + minutes;
          }
          $("#endTimePerson").val(hours + ":" + minutes);
          // if (value != "") {
          //   date.month = date.month - 1;
          //   endT.config.min = date;
          // } else {
          //   endT.config.min = begT.config.min;
          // }
        },
      });
      // 结束时间
      var endT = laydate.render({
        elem: "#endTimePerson",
        type: "time",
        format: "HH:mm",
        ready: function (value) {
          formatminutes($("#endDatePerson").val());
        },
        done: function (value, date) {
          // if (value != "") {
          //   date.month = date.month - 1;
          //   begT.config.max = date;
          // } else {
          //   begT.config.max = endT.config.max;
          // }
        },
      });
      //时间控件自定义
      function formatminutes(date) {
        var aa = $(".laydate-time-list li ol")[0];
        var bb = $(".laydate-time-list li ol")[1];
        var showtime1 = $(aa).find("li");
        var showtime2 = $(bb).find("li");
        for (var i = 0; i < showtime1.length; i++) {
          var t00 = showtime1[i].innerText;
          if (
            t00 != "08" &&
            t00 != "09" &&
            t00 != "10" &&
            t00 != "11" &&
            t00 != "12" &&
            t00 != "13" &&
            t00 != "14" &&
            t00 != "15" &&
            t00 != "16" &&
            t00 != "17" &&
            t00 != "18"
          ) {
            showtime1[i].remove();
          }
        }
        for (var i = 0; i < showtime2.length; i++) {
          var t01 = showtime2[i].innerText;
          if (
            t01 != "00" &&
            t01 != "10" &&
            t01 != "20" &&
            t01 != "30" &&
            t01 != "40" &&
            t01 != "50"
          ) {
            showtime2[i].remove();
          }
        }
        $($(".laydate-time-list li p")[2]).remove(); //清除汉字秒
        $($(".laydate-time-list li ol")[2]).remove(); //清空秒
        $($(".laydate-time-list li ol")[2]).find("li").remove(); //清空秒
        // 重新获取下当前的li的个数  -- 处理过去时间不可选的情况
        var aaLi = $(aa).find("li").get();
        var bbLi = $(bb).find("li").get();
        var todayMonth = new Date().getMonth() + 1;
        var tomorrowdDay = new Date().getDate() + 1; // 23 ---> 24
        var tomorrowDate =
          new Date().getFullYear() +
          "-" +
          todayMonth +
          "-" +
          tomorrowdDay +
          " 00:00:00";
        var tomorrowTime = new Date(tomorrowDate).getTime();
        var inputTime = new Date($("#startDatePerson").val() || null).getTime();
        var Hours = new Date().getHours();
        var Minutes = new Date().getMinutes();
        console.log(startTimme);

        // 循环小时,添加禁止类名 layui-disabled -- 处理过去时间不可选的情况
        let circulateAA = function (params) {
          aaLi.forEach((value, index) => {
            let text = parseInt(value.innerText);
            if (inputTime > tomorrowTime) {
              // 选项时间大于明天时间全部可用
              $(value).removeClass("layui-disabled").css({
                "pointer-events": "",
              });
            } else if (inputTime < tomorrowTime && text < Hours) {
              $(value).addClass("").addClass("layui-disabled").css({
                "pointer-events": "",
              });
            }
            console.log("aaLi", text);
          });
        };

        // 循环分钟,添加禁止类名 layui-disabled -- 处理过去时间不可选的情况

        let circulateBB = function (params) {
          bbLi.forEach((value, index) => {
            // $(value).removeClass('layui-this')
            let text = parseInt(value.innerText);
            if (inputTime > tomorrowTime) {
              // 选项时间大于明天时间全部可用
              $(value).removeClass("layui-disabled").css({
                "pointer-events": "",
              });
            } else if (inputTime < tomorrowTime) {
              $(value).removeClass("layui-this");
              if (Hours > 18) {
                console.log("inputTime < tomorrowTime");
                $(value).addClass("").addClass("layui-disabled").css({
                  "pointer-events": "none",
                });
              } else if (params && Hours == params && text < Minutes) {
                // 当选择当前小时且相等时,要做禁用准备
                console.log("inputTime < tomorrowTime");
                $(value).addClass("").addClass("layui-disabled").css({
                  "pointer-events": "none",
                });
              } else if (params && params > Hours && text < Minutes) {
                // 当天且时间再小时小时大于当前,要做去除禁用的准备
                $(value).removeClass("layui-disabled").css({
                  "pointer-events": "",
                });
              }
            }
            console.log("bbLi", text);
          });
        };

        // 解决点击闪动的问题
        let aaScrollTop = $(aa).scrollTop();
        console.log(aaScrollTop);
        $(aa).on("click", "li", function () {
          // 获取到点击的时间
          let curHours = $(this).text();
          circulateBB(curHours);

          // 解决闪动
          if ($(this).index() < 5) {
            $(this).parent().scrollTop(0);
          } else {
            $(this).parent().scrollTop($(aa).outerHeight());
          }
        });

        $(bb).on("click", "li", function (e) {
          // 获取到aa激活的索引,运行上面的逻辑即可
          let activeAAIndex = $(aa).children(".layui-this").index();
          if (activeAAIndex < 6) {
            $(aa).scrollTop(0);
          } else {
            $(aa).scrollTop($(aa).outerHeight());
          }
        });

        circulateAA();
        circulateBB();
      }

      //周六周日不可选
      function disabled_date(value, appointmentDate) {
        var mm = value.year + "-" + value.month + "-" + value.date;
        $(".laydate-theme-grid table tbody")
          .find('[lay-ymd="' + mm + '"]')
          .removeClass("layui-this");
        if (appointmentDate != null && appointmentDate != "") {
          var dates = appointmentDate.split(",");
          for (var i = 0; i < dates.length; i++) {
            if (dates[i] == "7") {
              dates[i] = 0;
            }
            $("table>tbody>tr")
              .find("td:eq(" + dates[i] + ")")
              .addClass("laydate-disabled");
          }
        }
      }
    }
    $("#userOption a cite").text(
      location.search.substr(location.search.indexOf("=") + 1)
    );
    var txtData;
    var year = null,
      week = null;
    // start添加sessionStorage 存储
    var infoData = "";
    infoData = JSON.parse(sessionStorage.getItem("objData"));
    if (infoData == "" || infoData == null) {
      var obj = { year: year, weekStart: week };
      sessionStorage.setItem("objData", JSON.stringify(obj));
      infoData = JSON.parse(sessionStorage.getItem("objData"));
    }

    getmeetingTime(infoData.year, infoData.weekStart);
    getPerson(infoData.year, infoData.weekStart);
    // end添加sessionStorage 存储

    // getmeetingTime(year, week);

    // 渲染公共日程
    function getmeetingTime(year, week) {
      $.ajax({
        url: base_url + "/meeting/list",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        async: true,
        dataType: "json",
        type: "get",
        data: { year: year, week: week },
        success: function (res) {
          if (res.type == "success") {
            txtData = res.data;
            var resData = txtData.data;
            var state = 1;
            getWeekStartDate(resData, state);
            $(".aMmondayGG").html("");
            $(".pMmondayGG").html("");
            $(".aMtuesdayGG").html("");
            $(".pMtuesdayGG").html("");
            $(".aMwednesdayGG").html("");
            $(".pMwednesdayGG").html("");
            $(".aMthursdayGG").html("");
            $(".pMthursdayGG").html("");
            $(".aMfridayGG").html("");
            $(".pMfridayGG").html("");
            if (
              resData == 0 ||
              resData.data == 0 ||
              resData.length == 0 ||
              resData == null
            ) {
            } else {
              getContInfoItem(resData, state);
            }
          }
        },
      });
    }
    // 渲染个人日程
    function getPerson(year, week) {
      $.ajax({
        url: base_url + "/agenda/slectMeeting",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        async: true,
        dataType: "json",
        type: "get",
        data: { year: year, week: week },
        success: function (res) {
          if (res.type == "success") {
            var agendaTxtData = res.data;
            var resData = agendaTxtData.data;
            var state = 2;
            $(".technicalReviewTit").html(
              agendaTxtData.year + "年" + "第" + agendaTxtData.MonthWeek + "周"
            );
            localStorage.setItem("year", [
              agendaTxtData.theyear,
              agendaTxtData.afteryear,
              agendaTxtData.start,
              agendaTxtData.ending,
            ]);
            getWeekStartDate(resData, state);
            getdiffdate(agendaTxtData.startdate, agendaTxtData.dateclosed);
            $(".aMmondayGR").html("");
            $(".pMmondayGR").html("");
            $(".aMtuesdayGR").html("");
            $(".pMtuesdayGR").html("");
            $(".aMwednesdayGR").html("");
            $(".pMwednesdayGR").html("");
            $(".aMthursdayGR").html("");
            $(".pMthursdayGR").html("");
            $(".aMfridayGR").html("");
            $(".pMfridayGR").html("");
            if (
              resData == 0 ||
              resData.data == 0 ||
              resData.length == 0 ||
              resData == null
            ) {
            } else {
              getContInfoItem(resData, state);
            }
          }
        },
      });
    }
    var now = new Date(); //当前日期
    var nowDayOfWeek = now.getDay(); //今天本周的第几天
    var nowDay = now.getDate(); //当前日
    var nowMonth = now.getMonth(); //当前月
    var nowYear = now.getYear(); //当前年
    nowYear += nowYear < 2000 ? 1900 : 0; //
    var lastMonthDate = new Date(); //上月日期
    lastMonthDate.setDate(1);
    lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
    var lastYear = lastMonthDate.getYear();
    var lastMonth = lastMonthDate.getMonth();
    //格局化日期：yyyy-MM-dd
    function formatDate(date) {
      var myyear = date.getFullYear();
      var mymonth = date.getMonth() + 1;
      var myweekday = date.getDate();
      if (mymonth < 10) {
        mymonth = "0" + mymonth;
      }
      if (myweekday < 10) {
        myweekday = "0" + myweekday;
      }
      return myyear + "-" + mymonth + "-" + myweekday;
    }
    //获得本周的一周日期
    var count = 0,
      num = 0;
    function getWeekStartDate(resData, state) {
      var nowDayOfWeekData = "";
      nowDayOfWeekData = nowDayOfWeek + num;
      var weekStartDate = [];
      var dateArr = [];
      for (var i = 1; i < 6; i++) {
        weekStart = new Date(
          nowYear,
          nowMonth,
          nowDay - (nowDayOfWeekData - i)
        );
        weekStartDate.push(weekStart);
      }
      weekStartDate.forEach((item) => {
        var dataTime = formatDate(item);
        dateArr.push(dataTime);
      });
    }
    function getContInfoItem(resData, state) {
      var arr1 = [],
        arr2 = [],
        arr3 = [],
        arr4 = [],
        arr5 = [];
      var arrData1 = [],
        arrData2 = [],
        arrData3 = [],
        arrData4 = [],
        arrData5 = [];
      if (state == 1) {
        resData.forEach((item) => {
          switch (new Date(item.startTime).getDay()) {
            case 1:
              var dom = $(".aMmondayGG"),
                dom2 = $(".pMmondayGG");
              arr1.push(item);
              rendering(dom, dom2, arr1, state);
              break;
            case 2:
              var dom = $(".aMtuesdayGG"),
                dom2 = $(".pMtuesdayGG");
              arr2.push(item);
              rendering(dom, dom2, arr2, state);
              break;
            case 3:
              var dom = $(".aMwednesdayGG"),
                dom2 = $(".pMwednesdayGG");
              arr3.push(item);
              rendering(dom, dom2, arr3, state);
              break;
            case 4:
              var dom = $(".aMthursdayGG"),
                dom2 = $(".pMthursdayGG");
              arr4.push(item);
              rendering(dom, dom2, arr4, state);
              break;
            case 5:
              var dom = $(".aMfridayGG"),
                dom2 = $(".pMfridayGG");
              arr5.push(item);
              rendering(dom, dom2, arr5, state);
              break;
          }
        });
      } else if (state == 2) {
        resData.forEach((item) => {
          switch (new Date(item.startTime).getDay()) {
            case 1:
              var dom = $(".aMmondayGR"),
                dom2 = $(".pMmondayGR");
              arrData1.push(item);
              rendering(dom, dom2, arrData1, state);
              break;
            case 2:
              var dom = $(".aMtuesdayGR"),
                dom2 = $(".pMtuesdayGR");
              arrData2.push(item);
              rendering(dom, dom2, arrData2, state);
              break;
            case 3:
              var dom = $(".aMwednesdayGR"),
                dom2 = $(".pMwednesdayGR");
              arrData3.push(item);
              rendering(dom, dom2, arrData3, state);
              break;
            case 4:
              var dom = $(".aMthursdayGR"),
                dom2 = $(".pMthursdayGR");
              arrData4.push(item);
              rendering(dom, dom2, arrData4, state);
              break;
            case 5:
              var dom = $(".aMfridayGR"),
                dom2 = $(".pMfridayGR");
              arrData5.push(item);
              rendering(dom, dom2, arrData5, state);
              break;
          }
        });
      }
    }

    function rendering(dom, dom2, array, state) {
      if (state == 1) {
        var str = "",
          str2 = "";
        array.forEach((item) => {
          var time = item.startTime.split(" ")[1].substring(0, 5);
          if (item.amPm == 1) {
            if (item.meetingStatus == 1) {
              str +=
                "<li data-id=" +
                item.id +
                ">" +
                "<div>" +
                "<span>" +
                time +
                "</span>" +
                "<span>" +
                item.meetingHeadline +
                ",</span>" +
                '<span class="name">' +
                item.site +
                "</span>" +
                "<p>" +
                meetingTypeFun(item) +
                "</p>" +
                "</div>" +
                '<img src="../../layuiadmin/images/newIcon.png" class="newIconImg"/>' +
                // getDel(item) +
                "</li>";
            } else {
              str +=
                "<li data-id=" +
                item.id +
                ">" +
                "<div>" +
                "<span>" +
                time +
                "</span>" +
                "<span>" +
                item.meetingHeadline +
                ",</span>" +
                '<span class="name">' +
                item.site +
                "</span>" +
                "<p>" +
                meetingTypeFun(item) +
                "</p>" +
                "</div>" +
                // getDel(item) +
                "</li>";
            }
          } else if (item.amPm == 2) {
            if (item.meetingStatus == 1) {
              str2 +=
                "<li data-id=" +
                item.id +
                " data.time=" +
                item.endtime +
                ">" +
                "<div>" +
                "<span>" +
                time +
                "</span>  " +
                "<span>" +
                item.meetingHeadline +
                ",</span>" +
                '<span class="name">' +
                item.site +
                "</span>" +
                "<p>" +
                meetingTypeFun(item) +
                "</p>" +
                "</div>" +
                '<img src="../../layuiadmin/images/newIcon.png" class="newIconImg"/>' +
                // getDel(item) +
                "</li>";
            } else {
              str2 +=
                "<li data-id=" +
                item.id +
                ">" +
                "<div>" +
                "<span>" +
                time +
                "</span>  " +
                "<span>" +
                item.meetingHeadline +
                ",</span>" +
                '<span class="name">' +
                item.site +
                "</span>" +
                "<p>" +
                meetingTypeFun(item) +
                "</p>" +
                "</div>" +
                // getDel(item) +
                "</li>";
            }
          }
        });
        dom.html(str);
        dom2.html(str2);
      } else if (state == 2) {
        var strAM = "",
          strPM = "";
        array.forEach((item, index) => {
          var timePerson = item.startTime.split(" ")[1].substring(0, 5);
          if (item.amPmType == "1") {
            strAM +=
              "<li data-id=" +
              item.uuid +
              ">" +
              "<div>" +
              "<span>" +
              timePerson +
              "</span>  " +
              "<span>" +
              item.title +
              ",</span>" +
              '<span class="name">' +
              item.site +
              "</span>" +
              '<p><i class="personalSchedule">个人日程</i></p>' +
              "</div>" +
              getDelPerson(item) +
              "</li>";
          } else if (item.amPmType == "2") {
            strPM +=
              "<li  data-id=" +
              item.uuid +
              ">" +
              "<div>" +
              "<span>" +
              timePerson +
              "</span>  " +
              "<span>" +
              item.title +
              ",</span>" +
              '<span class="name">' +
              item.site +
              "</span>" +
              '<p><i class="personalSchedule">个人日程</i></p>' +
              "</div>" +
              getDelPerson(item) +
              "</li>";
          }
        });
        dom.html(strAM);
        dom2.html(strPM);
      }
    }
    // 会议删除按钮
    function getDel(item) {
      //获取当前时间
      let timestamp = new Date().getTime();
      //获取计划时间
      let d = new Date(item.endTime);
      let t = d.getTime(d);

      if (t > timestamp) {
        return (
          '<em class="layui-icon layui-icon-delete deletePersonalSchedule"  onclick = deletePersonalSchedulee("' +
          item.id +
          '",this);></em>'
        );
      } else {
        return "";
      }
    }
    //个人日程删除按钮
    function getDelPerson(item) {
      //获取当前时间
      let timestamp = new Date().getTime();
      //获取计划时间
      let d = new Date(item.endTime);
      let t = d.getTime(d);

      if (t > timestamp) {
        return (
          '<em class="layui-icon layui-icon-delete deletePersonalSchedule"  onclick = deletePersonalSchedule("' +
          item.uuid +
          '",this);></em>'
        );
      } else {
        return "";
      }
    }
    // 会议分类
    function meetingTypeFun(item) {
      if (item.type == "线上会议") {
        return (
          '<i class="offLineMeetings"  onclick = demoTestt("' +
          item.id +
          '","' +
          item.userMeetingId +
          '",this);>' +
          item.type +
          "</i>"
        );
      } else if (item.type == "线下内部会议") {
        return (
          '<i class="publicMeetings"  onclick = demoTestt("' +
          item.id +
          '","' +
          item.userMeetingId +
          '",this);>' +
          item.type +
          "</i>"
        );
      } else if (item.type == "线下外部会议") {
        return (
          '<i class="offLineOutMeetings"  onclick = demoTestt("' +
          item.id +
          '","' +
          item.userMeetingId +
          '",this);>' +
          item.type +
          "</i>"
        );
      }
    }

    //左边切换
    var weekNumer = 0;
    $(".leftBtn").click(function () {
      var yearItem = localStorage.getItem("year");
      var year = yearItem.split(",")[0];
      var weekStart = yearItem.split(",")[2];
      var obj = { year: year, weekStart: weekStart };

      sessionStorage.setItem("objData", JSON.stringify(obj));
      var infoData = JSON.parse(sessionStorage.getItem("objData"));
      getmeetingTime(infoData.year, infoData.weekStart);
      getPerson(infoData.year, infoData.weekStart);
    });
    //右边切换
    $(".rightBtn").click(function () {
      // num = --count*7;
      var yearItem = localStorage.getItem("year");
      var year = yearItem.split(",")[1];
      var weekEnding = yearItem.split(",")[3];
      var obj = { year: year, weekStart: weekEnding };
      sessionStorage.setItem("objData", JSON.stringify(obj));
      var infoData = JSON.parse(sessionStorage.getItem("objData"));
      getmeetingTime(infoData.year, infoData.weekStart);
      getPerson(infoData.year, infoData.weekStart);
    });
    //点击新增  修改
    $(".rowTxt li").on("click", function () {
      $(".model").show();
    });
    $("#addSchedule").click(function () {
      layer.open({
        title: '<i class="fa fa-plus"></i>&nbsp;个人日程',
        type: 1,
        fix: false,
        skin: "addPersonalScheduleForm",
        area: ["800px", "700px"],
        // 宽高
        content: $("#addPersonalScheduleForm").html(),
        success: function (layero, index) {
          initDateCtrl();
          initFileMultipleCtrl();
          $.ajax({
            url: base_url + "/agenda/getAgendaInfoUuid",
            async: false,
            type: "post",
            contentType: "application/json; charset=UTF-8",
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            dataType: "json",
            // data:data,
            success: function (data) {
              if ((data.type = "200")) {
                addUid = data.data.uuid;
              }
            },
          });
          // 添加日程
          form.on("submit(formDemo)", function (data) {
            var field = data.field; //获取提交的字段
            if (addUid) {
              field.uuid = addUid;
              console.log(field.uuid);
            } else {
              field.uuid = addUid;
              console.log(field.uuid);
            }
            var startHour = field.starTime.split(":")[0];
            startTime = field.startDate + " " + field.starTime + ":00";
            endTime = field.endDate + " " + field.endTime + ":00";
            if (startHour < 12) {
              field.amPmType = "1";
            } else {
              field.amPmType = "2";
            }
            $.ajax({
              url: base_url + "/agenda/addAgendaInfo",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              async: false,
              type: "post",
              contentType: "application/json; charset=UTF-8",
              dataType: "json",
              data: JSON.stringify({
                uuid: field.uuid,
                title: field.title,
                startTime: startTime,
                endTime: endTime,
                site: field.address,
                remark: field.remark,
                amPmType: field.amPmType,
              }),
              success: function (data) {
                if ((data.type = "success")) {
                  // 添加成功
                  layer.msg(data.message, { icon: 6 });
                } else {
                  layer.msg(data.message, { icon: 5 });
                }
              },
            });
          });
        },
      });
    });

    $(".layui-btn.layuiadmin-btn-list").on("click", function () {
      var type = $(this).data("type");
      active[type] ? active[type].call(this) : "";
    });
    $(".closeBtn").on("click", function () {
      $(".model").hide();
      $("#demoList").html("");
      $(".model .layui-input")
        .removeClass("layui-disabled")
        .removeAttr("disabled");
      $(".model .layui-textarea")
        .removeClass("layui-disabled")
        .removeAttr("disabled");
      form.val("layuiadmin-app-form-list", {
        title: "",
        startDate: "",
        starTime: "",
        endDate: "",
        endTime: "",
        address: "",
        remark: "",
      });
    });
    //获取两日期之间日期列表函数
    function getdiffdate(stime, etime) {
      //初始化日期列表，数组
      var diffdate = new Array();
      var i = 0;
      //开始日期小于等于结束日期,并循环
      while (stime <= etime) {
        diffdate[i] = stime;
        //获取开始日期时间戳
        var stime_ts = new Date(stime).getTime();
        //增加一天时间戳后的日期
        var next_date = stime_ts + 24 * 60 * 60 * 1000;
        //拼接年月日，这里的月份会返回（0-11），所以要+1
        var next_dates_y = new Date(next_date).getFullYear() + "-";
        var next_dates_m =
          new Date(next_date).getMonth() + 1 < 10
            ? "0" + (new Date(next_date).getMonth() + 1) + "-"
            : new Date(next_date).getMonth() + 1 + "-";
        var next_dates_d =
          new Date(next_date).getDate() < 10
            ? "0" + new Date(next_date).getDate()
            : new Date(next_date).getDate();
        stime = next_dates_y + next_dates_m + next_dates_d;
        //增加数组key
        i++;
      }
      var html = "";
      for (var item in diffdate) {
        var array = diffdate[item].split("-");
        var ndate = new Date(array[0], parseInt(array[1] - 1), array[2]);
        var weekArray = new Array(
          "星期日",
          "星期一",
          "星期二",
          "星期三",
          "星期四",
          "星期五",
          "星期六"
        );
        var weekDay = weekArray[ndate.getDay()];
        html +=
          '<div class="theadBox"><span>' +
          diffdate[item] +
          "</span><span>" +
          weekDay +
          "</span></div>";
      }
      $(".thead").html('<div class="theadDiv"></div>' + html);
    }
    // 上传文件
    $(".uploadFileBtn").on("click", function () {
      layer.open({
        type: 2,
        title: "上传附件",
        content: "uploadFile.html?uuid=" + uuid,
        area: ["80%", "80%"],
        btn: ["确定", "取消"],
        yes: function (index, layero) {
          //点击确认触发 iframe 内容中的按钮提交
          var submit = layero.find("iframe").contents().find("#recordSubmit");
          $(".uploadBox").html(
            layero.find("iframe").contents().find(".uploadFile").html()
          );
          submit.click();
        },
      });
    });
    // 个人日程详情
    var addUid = "";
    $(document).on("click", ".personalSchedule", function (e) {
      addUid = $(this).parents("li").attr("data-id");
      console.log(addUid);
      layer.open({
        title: '<i class="fa fa-plus"></i>&nbsp;个人日程',
        type: 1,
        fix: false,
        skin: "addPersonalScheduleForm",
        area: ["800px", "700px"],
        // 宽高
        content: $("#addPersonalScheduleForm").html(),
        success: function (layero, index) {
          $.ajax({
            url: base_url + "/agenda/selectAgendaInfoByUuid",
            async: false,
            type: "POST",
            contentType: "application/json",
            data: JSON.stringify({ uuid: addUid }),
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            success: function (data) {
              initDateCtrl();
              initFileMultipleCtrl();
              var data = data.data.personalAgenda;
              var startTimeStr = data.startTime;
              var startDate = startTimeStr.split(" ")[0];
              var starTime = startTimeStr.split(" ")[1].substring(0, 5);
              var endDate = data.endTime.split(" ")[0];
              var endTime = data.endTime.split(" ")[1].substring(0, 5);
              var d = new Date(Date.parse(startTimeStr.replace(/-/g, "/")));
              var curDate = new Date();
              if (d <= curDate) {
                $(".addPersonalScheduleForm .layui-input").attr(
                  "disabled",
                  "disabled"
                );
                $(".addPersonalScheduleForm .layui-textarea").attr(
                  "disabled",
                  "disabled"
                );
              }
              form.val("layuiadmin-app-form-list", {
                title: data.title,
                startDate: startDate,
                starTime: starTime,
                endDate: endDate,
                endTime: endTime,
                address: data.site,
                remark: data.remark,
              });
              for (var item in data.agendaFileList) {
                var tr = $(
                  [
                    '<tr data-id="' +
                      data.agendaFileList[item].minioFileName +
                      '">',
                    "<td>" + data.agendaFileList[item].fileName + "</td>",

                    "<td>" + data.agendaFileList[item].fileSize + "</td>",
                    "<td>100%</td>",
                    "<td>" + data.agendaFileList[item].fileStatus + "</td>",
                    "<td>",
                    '<button class="layui-btn layui-btn-xs layui-btn-danger downLoad">下载</button>',
                    "</td>",
                    "</tr>",
                  ].join("")
                );
                tr.find(".downLoad").on("click", function () {
                  var uuidTrTs = $(this).parent().parent().attr("data-id");
                  window.location.href = uuidTrTs;
                  // $.ajax({
                  //   url:
                  //     base_url +
                  //     "/agenda/downLoadAgendaAttachFileByFileUuid?uuid=" +
                  //     uuidTrTs,
                  //   async: false,
                  //   type: "GET",
                  //   headers: {
                  //     Accept: "application/json; charset=utf-8",
                  //     Authorization: layui.sessionData("userToken").key,
                  //   },
                  //   success: function (data) {
                  //     window.location.href =
                  //       base_url +
                  //       "/agenda/downLoadAgendaAttachFileByFileUuid?uuid=" +
                  //       uuidTrTs;
                  //   },
                  // });
                  return false;
                });
                $("#demoList").append(tr);
              }
            },
          });
        },
      });
    });
    exports("home", {});
  }
);

// 会议日程详情
var result = true;
function demoTestt(id, userMeetingId, obj) {
  var $ = layui.$,
    form = layui.form;
  $(obj).parent().parent().next("img").remove();
  layer.open({
    title: '<i class="fa fa-plus"></i>&nbsp;会议信息',
    type: 1,
    fix: false,
    skin: "layui-layer-rim",
    area: ["40%", "65%"],
    // 宽高
    content: $("#meetingInformationForm").html(),
    success: function (layero, index) {
      $.ajax({
        url: base_url + "/meeting/" + id,
        async: false,
        type: "GET",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        success: function (data) {
          var data = data.data,
            dataJson = {},
            startDate = data.startTime.split(" ")[0],
            startTime = data.startTime.split(" ")[1].substring(0, 5),
            endTime = data.endTime.split(" ")[1].substring(0, 5);
          dataJson.meetingTime =
            startDate + "   " + startTime + " - " + endTime;
          dataJson.title = data.meetingHeadline;
          dataJson.address = data.site;
          dataJson.meetingUserid = data.orgUserNumber;
          dataJson.meetingRemarks = data.remarks;
          dataJson.ackMsgs = data.ackMsgs;
          if (data.inviteLink == "") {
            $(".enterMeeting").hide();
          } else {
            // window.open(data.inviteLink);
            $(".enterMeeting").attr(
              "href",
              "./launch.html?mid=" +
                id +
                "&uid=" +
                layui.sessionData("userName").key +
                "&token=" +
                layui.sessionData("userToken").key
            );
            // $(".enterMeeting").attr("href", data.inviteLink);
            // $(".enterMeeting").on("click", function () {
            //   $(this).attr("href", data.inviteLink);
            // });
          }
          $(".meetingNotice").on("click", function () {
            window.location.href = base_url + "/meeting/download/2/" + data.id;
          });
          form.val("meetingInformationForm", dataJson);
        },
      });
    },
  });
  $.ajax({
    url: base_url + "/meeting/updMeetingStatus/" + userMeetingId,
    async: false,
    type: "GET",
    headers: {
      Accept: "application/json; charset=utf-8",
      Authorization: layui.sessionData("userToken").key,
    },
    success: function (data) {
      if (data.type == "type") {
        console.log(data.message);
      }
    },
  });
}
function deletePersonalSchedule(id, obj) {
  var $ = layui.$;
  $.ajax({
    url: base_url + "/agenda/deleteAgendaInfoByUuid",
    async: false,
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify({ uuid: id }),
    headers: {
      Accept: "application/json; charset=utf-8",
      Authorization: layui.sessionData("userToken").key,
    },
    success: function (data) {
      if ((data.type = "success")) {
        $(obj).parents("li").remove();
        layer.msg(data.message, { icon: 6 });
      } else {
        layer.msg(data.message, { icon: 5 });
      }
    },
  });
}
function deletePersonalSchedulee(id, obj) {
  var $ = layui.$;
  $.ajax({
    url: base_url + "/meeting/delete/" + id,
    async: false,
    type: "GET",
    headers: {
      Accept: "application/json; charset=utf-8",
      Authorization: layui.sessionData("userToken").key,
    },
    success: function (data) {
      if ((data.type = "success")) {
        $(obj).parents("li").remove();
        layer.msg(data.message, { icon: 6 });
      } else {
        layer.msg(data.message, { icon: 5 });
      }
    },
  });
}
